//
//  AnimatedAnnotationView.m
//  Category_demo2D
//
//  Created by 刘博 on 13-11-8.
//  Copyright (c) 2013年 songjian. All rights reserved.
//

#import "AnimatedAnnotationView.h"
//#import "AnimatedAnnotation.h"

#define kWidth          60.f
#define kHeight         60.f
#define kTimeInterval   0.15f
@interface AnimatedAnnotationView()
@property (nonatomic)CGRect rect;

@end
@implementation AnimatedAnnotationView
@synthesize imageView = _imageView;

#pragma mark - Life Cycle
- (id)initWithAnnotation:(id<MAAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier WithFrame:(CGRect )rect
{
    self.rect = rect;
    
    return [self initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
}
- (id)initWithAnnotation:(id<MAAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    
    if (self)
    {
        [self setBounds:CGRectMake(0.f, 0.f, _rect.size.width, _rect.size.height)];
        [self setBackgroundColor:[UIColor clearColor]];
        
        self.imageView = [[UIImageView alloc] initWithFrame:self.bounds];
        [self addSubview:self.imageView];
        self.imageView.image = [UIImage imageNamed:@"scanner"];
        CABasicAnimation* rotationAnimation;
        rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
        
                //旋转角度
        
        rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI];
        
                //每次旋转的时间（单位秒）
        
        rotationAnimation.duration = 1.5;
        
        rotationAnimation.cumulative = YES;
        
                //重复旋转的次数，如果你想要无数次，那么设置成MAXFLOAT
        
        rotationAnimation.repeatCount = MAXFLOAT;
        
        [self.imageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
        
        
        
        
        
        
    }
    
    return self;
}

#pragma mark - Utility

- (void)updateImageView
{
//    AnimatedAnnotation *animatedAnnotation = (AnimatedAnnotation *)self.annotation;
    
//    if ([self.imageView isAnimating])
//    {
//        [self.imageView stopAnimating];
//    }
//
//    self.imageView.animationImages      = animatedAnnotation.animatedImages;
//    self.imageView.animationDuration    = kTimeInterval * [animatedAnnotation.animatedImages count];
//    self.imageView.animationRepeatCount = 0;
//    [self.imageView startAnimating];
}

#pragma mark - Override

- (void)setAnnotation:(id<MAAnnotation>)annotation
{
    [super setAnnotation:annotation];
    
    [self updateImageView];
}

@end
